<template>
  <div>
    <br />
    <el-tabs v-model="tabIndex" type="card" @tab-click="handleClick">
      <el-tab-pane label="车辆统计" name="0"></el-tab-pane>
    </el-tabs>

    <el-row>
      <div class="tableheader">
        <span class="g-title">车辆汇总({{totals}}个）</span>
        <el-table :data="carList" :border="true">
          <el-table-column prop="index" fixed label="序号" align="center"></el-table-column>

          <el-table-column prop="companyName" label="单位名称" header-align="center" width="200">
            <template slot-scope="scope">
              <el-button @click="editCarconfig(scope.row)" type="text">{{scope.row.companyName}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="syCount" label="合计" align="center"></el-table-column>
          <el-table-column prop="ZzsjgbycSy" label="在职省级干部用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'ZzsjgbycSy')"
                type="text"
              >{{scope.row.ZzsjgbycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="LtxzsjgbycSy" label="离退休正省级干部用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'LtxzsjgbycSy')"
                type="text"
              >{{scope.row.LtxzsjgbycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="LxfsjgbycSy" label="离休副省级干部用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'LxfsjgbycSy')"
                type="text"
              >{{scope.row.LxfsjgbycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="TxfsjgbycSy" label="退休副省级干部用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'TxfsjgbycSy')"
                type="text"
              >{{scope.row.TxfsjgbycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="DxhswgwycSy" label="定向化实物保障岗位用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'DxhswgwycSy')"
                type="text"
              >{{scope.row.DxhswgwycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="JytxycSy" label="机要通信用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'JytxycSy')"
                type="text"
              >{{scope.row.JytxycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="YjbzycSy" label="应急用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'YjbzycSy')"
                type="text"
              >{{scope.row.YjbzycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="JytxyyjhyycSy" label="机要通信与应急合一用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'JytxyyjhyycSy')"
                type="text"
              >{{scope.row.JytxyyjhyycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="LtxgbgljgycSy" label="离退休干部管理机构用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'LtxgbgljgycSy')"
                type="text"
              >{{scope.row.LtxgbgljgycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="DyscdcycSy" label="调研视察督察用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'DyscdcycSy')"
                type="text"
              >{{scope.row.DyscdcycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="ZwjdycSy" label="政务接待用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'ZwjdycSy')"
                type="text"
              >{{scope.row.ZwjdycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="ZfzqycSy" label="执法执勤用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'ZfzqycSy')"
                type="text"
              >{{scope.row.ZfzqycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="TzzyjsycSy" label="特种专业技术用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'TzzyjsycSy')"
                type="text"
              >{{scope.row.TzzyjsycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="YwycSy" label="业务用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'YwycSy')"
                type="text"
              >{{scope.row.YwycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="BcSy" label="班车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'BcSy')"
                type="text"
              >{{scope.row.BcSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="HqfwycSy" label="后勤服务用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'HqfwycSy')"
                type="text"
              >{{scope.row.HqfwycSy}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="QtycSy" label="其他用车" align="center">
            <template slot-scope="scope">
              <el-button
                @click="showCarlist(scope.row.companyId,'QtycSy')"
                type="text"
              >{{scope.row.QtycSy}}</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-row style="padding: 32px 16px;">
          <el-col>
            <el-pagination
              background
              layout="total, sizes, prev, pager, next, jumper"
              :page-size="cl_pageSize"
              :total="totals"
              :current-page="cl_pageNo"
              @current-change="getData"
              @size-change="cl_pageSizeChange"
            ></el-pagination>
          </el-col>
        </el-row>
      </div>
    </el-row>
  </div>
</template>
<style>
[v-cloak] {
  display: none;
}

@media screen and (min-width: 992px) {
  .modal-dialog {
    width: 992px;
  }
}

.g-title {
  height: 20px;
  padding-left: 8px;
  line-height: 22px;
  font-size: 16px;
  font-weight: 400;
  border-left: 2px solid #f54e40;
  margin: 10px 0;
  display: inline-block;
}

.el-table th {
  background-color: #f5f7fa;
}

.el-table__body tr,
.el-table__body td {
  padding: 0;
  height: 50px;
}

.el-dialog {
  -webkit-transform: none;
  transform: none;
  left: 0;
  position: relative;
  margin: 0 auto;
  background: #eef1f6;
}

.el-dialog__body {
  background-color: white;
  margin: 0px 10px;
}

.eluploadwrapper {
  display: inline-block;
  margin-left: 10px;
}
.upload_exl .el-upload,
.upload_exl .el-upload-dragger {
  width: 100%;
}

.upload_exl .el-upload-dragger .el-button {
  margin-top: 76px;
}
.mod_box {
  padding: 20px;
}
.mod_title {
  padding: 20px 0;
}
.g-title {
  height: 20px;
  padding-left: 8px;
  line-height: 22px;
  font-size: 16px;
  font-weight: 400;
  border-left: 2px solid #f54e40;
  margin: 10px 0;
  display: inline-block;
}
</style>
<script>
import { axios } from "@/api/axios";
import { listJson } from "@/api/car";
import { axios_req } from "@/api/carcommon";
import modDwCar from "../management/carconfig/components/modDwCar/index";
import carInfos from "../companyset/components/carinfo/index";
import addUpdate from "../companyset/components/addupdate/index";
import { mapGetters } from "vuex";
export default {
  components: { modDwCar, carInfos, addUpdate },
  computed: {
    ...mapGetters(["userInfo"]),
    ...mapGetters(["selectedComIds"])
  },
  watch: {
    //监听左侧单位勾选 重新获取数据
    selectedComIds() {
      this.pageNo = 1;
      this.fetchData();
    },
    selectData(data) {
      this.selectRow = [];
      if (data.length > 0) {
        data.forEach((item, index) => {
          // console.log(item)
          this.selectRow.push(
            item.index - (this.pageNo - 1) * this.pageSize - 1
          );
        });
      }
    }
  },
  data: function() {
    return {
      upload: {},
      tabIndex: "0",
      ccode: false,
      dialogVisible: false,
      show: false,
      imageUrl: "",
      add_update: false,
      daoruType: false,
      total: 1,
      totals: 0,
      cl_total: 3,
      pageNo: 1,
      cl_pageNo: 1,
      status: 0,
      pageSize: 10,
      cl_pageSize: 10,
      carId: 0,
      listData: [], //全部数据
      listDataSelected: [], //选中数据
      formData: [],
      carList: [],
      carinfo: {},
      headers: {
        cookie: ""
      },
      addMode: false, //是新增还是编辑模式
      //角色
      rules: {},

      companyId: 383,
      searchMess: "",
      top: 1,
      down: 1,
      edits: 1,
      usertype: 0,

      update: 0,
      search: [], //搜索类型数组
      searchData: {
        companyName: "",
        carCode: "",
        useAttrIds: "",
        carTypeIds: "",
        carClassIds: "",
        zuoWeiIds: "",
        getTypeIds: "",
        regDateStart: "",
        regDateEnd: "",
        discharge1: "",
        discharge2: "",
        goNum1: "",
        goNum2: ""
      },
      Cartotal: 0,
      CarpageNo: 1,
      CarpageSize: 10,
      listCarData: [],
      carsType: false,
      searchs: {
        dongLiType: [],
        zuoWeiNum: [],
        useType: [],
        getCarType: [],
        carType: []
      }, //下拉搜索类型数组
      kinds: {},
      webUploadUrl: "", //文件上传地址
      fileurl: "",

      htotal: 0,
      hpageNo: 1,
      hpageSize: 10,
      hlistData: [],
      hlistDataSelected: [],
      selectRow: [],
      selectData: [],
      fullscreenLoading: false
    };
  },
  created() {
    this.webUploadUrl = this.VUE_APP_BASE_API + "/common/webupload.shtml";
    this.status = "";
    if (this.userInfo.usertype == 3) {
      this.status = 1;
    } else {
      this.status = 0;
    }
    this.getsearchdata();
    this.usertype = this.userInfo.usertype;
    this.fetchData();
    this.getData();
    this.hfetchData();
  },
  methods: {
    //表头搜索
    handleFilterChange(filters) {
      //使用性质
      if (filters["useType"]) {
        this.searchData.useAttrIds = filters["useType"].join(",");
      }

      //车型
      if (filters["carType"]) {
        this.searchData.carTypeIds = filters["carType"].join(",");
      }

      //动力类型
      if (filters["dlclass"]) {
        this.searchData.carClassIds = filters["dlclass"].join(",");
      }

      //座位数
      if (filters["zuowei"]) {
        this.searchData.zuoWeiIds = filters["zuowei"].join(",");
      }

      //取得方式
      if (filters["getCarType"]) {
        this.searchData.getTypeIds = filters["getCarType"].join(",");
      }

      this.fetchData();
    },

    async hfetchData(pageNo) {
      if (pageNo) {
        this.hpageNo = pageNo;
      }
      let url = "/admin/company/listJson.do";
      let method = "get";
      let params = {
        pageNo: this.hpageNo,
        pageSize: this.hpageSize,
        companyName: this.searchMess
      };
      let data = await axios_req(url, method, params);
      this.hlistData = data.data;
      for (var i in this.hlistData) {
        this.hlistData[i].index =
          Number(i) + Number(this.hpageSize * (this.hpageNo - 1)) + 1;
      }
      this.htotal = data.total;
    },
    hpageSizeChange(newSize) {
      this.hpageSize = newSize;
      this.hpageNo = 1;
      this.hfetchData();
    },
    //表格多选
    hhandleSelectionChange(val) {
      this.hlistDataSelected.splice(0);
      val.forEach(e => {
        this.hlistDataSelected.push(e);
      });
    },

    onSuccess1(file) {
      if (!file) return;
      console.log(file);
      if (file.error == 0) {
        console.log(this.VUE_APP_BASE_API + file.url);
        this.fileurl = file.url;
      } else {
        this.$message("上传失败，请重试");
      }
    },
    onRemove() {
      this.fileurl = "";
    },
    onExceed() {
      this.$message("只能上传1个文件，请先移除已上传文件再上传");
    },
    beforeUpload(file) {
      var FileExt = file.name.replace(/.+\./, "");
      if (["xlsx"].indexOf(FileExt.toLowerCase()) === -1) {
        this.$message({
          type: "warning",
          message: "请上传后缀名为xlsx的文件！"
        });
        return false;
      }
    },

    async daoru() {
      if (this.fileurl == "") {
        this.$message("请上传文件");
        return;
      }
      let url = "/admin/car/import.do";
      let method = "post";
      let params = { dir: this.fileurl };
      let data = await axios_req(url, method, params);
      console.log(data);
      if (data.error == 0) {
        if (data.errorMsg) {
          data.errorMsg = data.errorMsg.replace(/^,+/, "").replace(/,+$/, "");
          this.$message({
            message: data.errorMsg
          });
        } else {
          this.$message({
            type: "success",
            message: "导入成功!"
          });
        }

        this.fileurl = "";
        this.$refs.upload.clearFiles();
        this.fetchData();
        this.daoruType = false;
      } else {
        this.$message({
          type: "info",
          message: "导入失败"
        });
        this.fileurl = "";
        this.fetchData();
      }
    },

    //搜索参数数组
    async getsearchdata() {
      let url = "/admin/car/viewJson.do";
      let method = "post";
      let params = {};
      let data = await axios_req(url, method, params);
      this.kinds = data;
      this.search.dongLiType = data.dongLiType;
      this.search.getCarType = data.getCarType;
      this.search.carType = data.carType;
      this.search.useType = data.useType;
      this.search.companyName = "";
      this.search.carId = "";

      this.setSearch("dongLiType");
      this.setSearch("zuoWeiNum");
      this.setSearch("useType");
      this.setSearch("getCarType");
      this.setSearch("carType");
    },
    setSearch(val) {
      this.searchs[val] = [];
      this.kinds[val].map((value, index, arry) => {
        this.searchs[val].push({ value: value.id, text: value.name });
      });
    },
    searchDatas() {
      this.fetchData();
    },
    handleClick(tab, event) {
      var sign = event.target.getAttribute("id").split("-")[1];

      if (sign == 0 || sign == 1) {
        this.display1 = "none";
        this.display2 = "block";
        this.display3 = "none";
        this.down = 0;
        this.edits = 0;
      } else if (sign == 6) {
        this.display1 = "none";
        this.display2 = "none";
        this.display3 = "block";
      } else {
        this.display1 = "block";
        this.display2 = "none";
        this.display3 = "none";
        this.down = 1;
        this.edits = 1;
      }

      if (sign == 0 || sign == 1 || sign == 6) {
        if (this.userInfo.usertype == 3) {
          this.status = 1;
        } else {
          this.status = 0;
        }
        this.fetchData();
      } else {
        this.status = 0;
        this.fetchData();
      }
    },
    mbdownload() {
      window.location.href =
        this.VUE_APP_BASE_API + "upload/temp/车辆导入模板.xlsx";
    },
    imports() {},
    async getData(pageNo) {
      if (pageNo) {
        this.cl_pageNo = pageNo;
      }
      let url = "/admin/carconfig/findDetails.do";
      let method = "post";
      let params = {
        pageNo: this.cl_pageNo,
        pageSize: this.cl_pageSize,
        companyName: this.searchMess,
        companyId:this.userInfo.comid
      };
      let data = await axios_req(url, method, params);
      this.carList = data.data;
      for (var i in this.carList) {
        this.carList[i].index =
          Number(i) + Number(this.cl_pageSize * (this.cl_pageNo - 1)) + 1;
      }
      this.totals = data.total;
    },
    showCarlist(val, name) {
      this.CarcompanyId = val;
      this.Carattrs = name;
      this.carsType = true;
      this.CarfetchData();
    },

    async CarfetchData(pageNo) {
      if (pageNo) {
        this.CarpageNo = pageNo;
      }
      let url = "/admin/carconfig/findCar.do";
      let method = "post";
      let params = {
        pageNo: this.CarpageNo,
        pageSize: this.CarpageSize,
        companyId: this.CarcompanyId,
        attrs: this.Carattrs
      };
      let data = await axios_req(url, method, params);
      this.listCarData = data.data;
      for (var i in this.listCarData) {
        this.listCarData[i].index =
          Number(i) + Number(this.CarpageSize * (this.CarpageNo - 1)) + 1;
      }
      this.Cartotal = data.total;
    },
    resetForm() {
      this.searchData.companyName = "";
      this.searchData.discharge1 = "";
      this.searchData.discharge2 = "";
      this.searchData.goNum1 = "";
      this.searchData.goNum2 = "";
      this.searchData.regDateStart = "";
      this.searchData.regDateEnd = "";
      this.fetchData();
    },
    //车辆信息
    async showinfo(info) {
      this.carId = info.id;
      this.ccode = true;
    },
    async getinfo(row) {},

    exportData() {
      if (this.listDataSelected.length == 0) {
        this.$message("请选择行数据");
        return;
      }

      var headers =
        "序号,机动车所有人,车辆号码,品牌型号,颜色,购置价格（万元）,排气量,登记日期,行驶里程,使用性质,车架号,发动机号,保险日期,年审日期,车型,动力类型,OBD代码,座位数,排放标准,经费来源,取得方式,备注信息";
      var data = this.listDataSelected.map(function(e) {
        return {
          id: e.index || "",
          companyName: e.companyName || "",
          carCode: e.carCode || "",
          pinpai: e.pinpai.replace(/\s*/g, "") || "",
          carColor: e.carColor || "",
          buyPrice: e.buyPrice || "",
          discharge: e.discharge || "",
          createDate: e.regDate || "",
          goNum: e.goNum || "",
          useType: e.useType || "",
          fromCode: e.fromCode || "",
          machineCode: e.machineCode || "",
          baoXianDate: e.baoXianDate || "",
          nianShenDate: e.nianShenDate || "",
          carType: e.carType || "",
          dlclass: e.dlclass || "",
          obdcode: e.obdcode || "",
          zuowei: e.zuowei || "",
          paiFang: e.paiFang || "",
          jingFei: e.jingFei || "",
          type: e.type || "",
          remark: e.remark || ""
        };
      });
      this.jsonToExcel(data, headers);
    },

    exportAll() {
      this.$confirm("是否全部导出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        // this.fullscreenLoading = true;
        if (this.searchData.regDateStart && this.searchData.regDateEnd) {
          var searchTime =
            this.searchData.regDateStart + "," + this.searchData.regDateEnd;
        } else if (
          (this.searchData.regDateStart && !this.searchData.regDateEnd) ||
          (!this.searchData.regDateStart && this.searchData.regDateEnd)
        ) {
          this.$message("请选择完整搜索日期");
          return;
        } else {
          var searchTime = "";
        }

        if (this.searchData.discharge1 && this.searchData.discharge2) {
          var dischargeData =
            this.searchData.discharge1 + "," + this.searchData.discharge2;
        } else if (
          (this.searchData.discharge1 && !this.searchData.discharge2) ||
          (!this.searchData.discharge1 && this.searchData.discharge2)
        ) {
          this.$message("请输入完整排气量范围");
          return;
        } else {
          var dischargeData = "";
        }

        if (this.searchData.goNum1 && this.searchData.goNum2) {
          var goNumData = this.searchData.goNum1 + "," + this.searchData.goNum2;
        } else if (
          (this.searchData.goNum1 && !this.searchData.goNum2) ||
          (!this.searchData.goNum1 && this.searchData.goNum2)
        ) {
          this.$message("请输入完整行驶里程范围");
          return;
        } else {
          var goNumData = "";
        }
        let params = {
          pageNo: this.pageNo,
          pageSize: 50,
          // status: this.status,
          companyName: this.searchData.companyName,
          carCode: this.searchData.carCode,
          carTypeIds: this.searchData.carTypeIds,
          carClassIds: this.searchData.carClassIds,
          useAttrIds: this.searchData.useAttrIds,
          zuoWeiIds: this.searchData.zuoWeiIds,
          getTypeIds: this.searchData.getTypeIds,
          searchTime: searchTime,
          goNums: goNumData,
          discharges: dischargeData,
          comIds: this.selectedComIds.join(",")
        };
        try {
          let data = [];
          //分段请求
          //每次请求数据大小
          let requestPageSize = 500;
          //总请求次数
          let requestTimes = Math.ceil(this.total / requestPageSize);
          params.pageSize = requestPageSize;
          params.pageNo = 1;
          let startTime = new Date().getTime();
          let loading = this.$loading({ text: "正在导出...0%" });
          for (let i = 0; i <= requestTimes; i++) {
            listJson(JSON.parse(JSON.stringify(params))).then(r => {
              data.push(...r.data);
              loading.text = `正在导出...${(
                (data.length / this.total) *
                100
              ).toFixed(1)}%`;
              if (data.length == this.total) {
                loading.close();
                console.log(
                  `分页大小：${requestPageSize}，请求次数：${requestTimes}，耗时：${(new Date().getTime() -
                    startTime) /
                    1000}秒`
                );
                this.onExportDataFinish(data);
              }
            });
            params.pageNo = i + 1;
          }
        } catch (error) {
          this.$message({
            message: "导出失败请重试",
            type: "error"
          });
          loading.close();
        }
      });
    },
    //全部数据请求完拼凑到一起后到回调导出方法
    onExportDataFinish(data) {
      data.sort((a, b) => b.id - a.id);
      for (var i in data) {
        data[i].index = Number(i) + Number(this.total * (this.pageNo - 1)) + 1;
      }
      this.fullscreenLoading = false;
      var headers =
        "序号,机动车所有人,车辆号码,品牌型号,颜色,购置价格（万元）,排气量,登记日期,行驶里程,使用性质,车架号,发动机号,保险日期,年审日期,车型,动力类型,OBD代码,座位数,排放标准,经费来源,取得方式,备注信息";
      var edata = data.map(function(e) {
        return {
          id: e.index || "",
          companyName: e.companyName || "",
          carCode: e.carCode || "",
          pinpai: e.pinpai ? e.pinpai.replace(/\s*/g, "") : "",
          carColor: e.carColor || "",
          buyPrice: e.buyPrice || "",
          discharge: e.discharge || "",
          createDate: e.regDate || "",
          goNum: e.goNum || "",
          useType: e.useType || "",
          fromCode: e.fromCode || "",
          machineCode: e.machineCode || "",
          baoXianDate: e.baoXianDate || "",
          nianShenDate: e.nianShenDate || "",
          carType: e.carType || "",
          dlclass: e.dlclass || "",
          obdcode: e.obdcode || "",
          zuowei: e.zuowei || "",
          paiFang: e.paiFang || "",
          jingFei: e.jingFei || "",
          type: e.type || "",
          remark: e.remark || ""
        };
      });
      this.jsonToExcel(edata, headers);
    },
    //json导出excel
    jsonToExcel(jsonData, headers) {
      //列标题，逗号隔开，每一个逗号就是隔开一个单元格
      var str = headers + "\n";
      //增加\t为了不让表格显示科学计数法或者其他格式
      for (var i = 0; i < jsonData.length; i++) {
        for (var item in jsonData[i]) {
          str += jsonData[i][item] + "\t,";
        }
        str += "\n";
      }
      //encodeURIComponent解决中文乱码
      var uri = "data:text/csv;charset=utf-8,\ufeff" + encodeURIComponent(str);
      //通过创建a标签实现
      var link = document.createElement("a");
      link.href = uri;
      //对下载的文件命名
      link.download = "车辆列表.csv";
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    },
    //编辑车辆信息
    async edit() {
      if (this.listDataSelected.length == 0) {
        this.$message("请选择行数据");
        return;
      } else if (this.listDataSelected.length >= 2) {
        this.$message("最多选一行");
        return;
      } else {
        this.carId = this.listDataSelected[0].id;
        this.update = 1;
        this.add_update = true;
      }
    },

    //新增按钮事件
    async add() {
      this.update = 0;
      this.ruleForm = {};
      this.add_update = true;
    },

    editCarconfig(val) {
      this.companyId = val.companyId;
      this.dialogVisible = false;
      this.editUrl =
        "/cars/admin/company/showCarconfig.do?id=" +
        val.companyId +
        "&top=1&down=0&edit=0";
      this.dialogVisible = true;
    },

    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    pageSizeChange(newSize) {
      this.pageSize = newSize;
      this.pageNo = 1;
      this.fetchData();
    },
    cl_pageSizeChange(newSize) {
      this.cl_pageSize = newSize;
      this.cl_pageNo = 1;
      this.getData();
    },
    CarpageSizeChange(newSize) {
      this.CarpageSize = newSize;
      this.CarpageNo = 1;
      this.CarfetchData();
    },

    //车辆列表
    async fetchData(pageNo) {
      if (pageNo) {
        this.pageNo = pageNo;
      }
      if (this.searchData.regDateStart && this.searchData.regDateEnd) {
        var searchTime =
          this.searchData.regDateStart + "," + this.searchData.regDateEnd;
      } else if (
        (this.searchData.regDateStart && !this.searchData.regDateEnd) ||
        (!this.searchData.regDateStart && this.searchData.regDateEnd)
      ) {
        this.$message("请选择完整搜索日期");
        return;
      } else {
        var searchTime = "";
      }

      if (this.searchData.discharge1 && this.searchData.discharge2) {
        var dischargeData =
          this.searchData.discharge1 + "," + this.searchData.discharge2;
      } else if (
        (this.searchData.discharge1 && !this.searchData.discharge2) ||
        (!this.searchData.discharge1 && this.searchData.discharge2)
      ) {
        this.$message("请输入完整排气量范围");
        return;
      } else {
        var dischargeData = "";
      }

      if (this.searchData.goNum1 && this.searchData.goNum2) {
        var goNumData = this.searchData.goNum1 + "," + this.searchData.goNum2;
      } else if (
        (this.searchData.goNum1 && !this.searchData.goNum2) ||
        (!this.searchData.goNum1 && this.searchData.goNum2)
      ) {
        this.$message("请输入完整行驶里程范围");
        return;
      } else {
        var goNumData = "";
      }
      console.log(this.status);
      let url = "/admin/car/listJson.do";
      let method = "post";
      let params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        // status: this.status,
        companyName: this.searchData.companyName,
        carCode: this.searchData.carCode,
        carTypeIds: this.searchData.carTypeIds,
        carClassIds: this.searchData.carClassIds,
        useAttrIds: this.searchData.useAttrIds,
        zuoWeiIds: this.searchData.zuoWeiIds,
        getTypeIds: this.searchData.getTypeIds,
        searchTime: searchTime,
        goNums: goNumData,
        discharges: dischargeData,
        comIds: this.selectedComIds.join(",")
      };
      console.log(params);
      let data = await axios_req(url, method, params);
      console.log(data);
      this.listData = data.data;
      for (var i in this.listData) {
        this.listData[i].index =
          Number(i) + Number(this.pageSize * (this.pageNo - 1)) + 1;
      }
      this.total = data.total;
      this.listDataSelected.splice(0);
    },
    //表格多选
    handleSelectionChange(val) {
      this.listDataSelected.splice(0);
      val.forEach(e => {
        this.listDataSelected.push(e);
      });

      this.selectData = val;
    },
    rowClass({ row, rowIndex }) {
      // console.log(rowIndex)
      if (this.selectRow.includes(rowIndex)) {
        return { "background-color": "rgba(185, 221, 249, 0.75)" };
      }
    },
    //删除确认
    check() {
      if (this.listDataSelected.length == 0) {
        this.$message("请选择行数据");
        return;
      }
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.del();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //车辆删除
    async del() {
      var del_str = "";
      this.listDataSelected.forEach(function(e) {
        del_str = del_str + "," + e.id;
      });
      del_str = del_str.replace(/^,+/, "").replace(/,+$/, "");
      let url = "/admin/car/removeCars.do";
      let method = "post";
      let params = {
        ids: del_str
      };
      let data = await axios_req(url, method, params);
      if (data.error == 0) {
        this.$message({
          type: "success",
          message: "删除成功!"
        });
        this.fetchData();
      } else {
        this.$message({
          type: "info",
          message: "删除失败"
        });
        this.fetchData();
      }
    }
  }
};
</script>
